/*
 * @Description: 
 * @Autor: 商晓彬
 * @Date: 2021-07-10 09:50:15
 * @LastEditors: 商晓彬
 * @LastEditTime: 2022-01-04 14:30:56
 */
import { Component, Injector, ViewChild } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { MessageService } from '@abp/message/message.service';
import { LeadCockpitServiceProxy } from '@shared/service-proxies/service-proxies';
import { finalize } from 'rxjs/operators';
@Component({
  selector: 'app-driver',
  templateUrl: './driver.component.html',
  styleUrls: ['./driver.component.less']
})
export class DriverComponent extends AppComponentBase {
    rescueData1: any;
    rescueData2: any;
    rescueMsg1 = {
        title: undefined,
        sum:undefined
    };
    rescueMsg2 = {
        title: undefined,
        sum:undefined
    };
    options = {
        // title: {
        //     display: true,
        //     text: 'My Title',
        //     fontSize: 16
        // },
        // legend: {
        //     position: 'bottom'
        // },
        tooltip: {
                trigger: 'item',
                formatter: function (params) {
                }
        },
    };
    barData1: any;
    barData2: any;
    private interval: any;//定时器对象
    messionIndex = 0;
    padIndex = 0;
    padMsg: any;
    padFlag: boolean = false;
    messionFlag: boolean = false;
    constructor(
        injector: Injector,
        private _messageService: MessageService,
        private _leadCockpitServiceProxy: LeadCockpitServiceProxy,
    ) {
        super(injector);
        
      
       
  }
    ngOnInit() {
        this.getCollection();
        this.getMute();
        this.getMession();
        this.getPad();
    }
    pageDown(type) {
        if (type == 1) {
            this.messionIndex = this.messionIndex - 2;
            //生产任务信息分页
            this.getMession();
        }
        if (type == 2) {
            this.padIndex = this.padIndex - 4;
            //PAD任务信息分页
            this.getPad();
        }
    }
    pageUp(type) {
        if (type == 1) {
            this.messionIndex = this.messionIndex + 2;
            //生产任务信息分页
            this.getMession();
        }
        if (type == 2) {
            this.padIndex = this.padIndex + 4;
            //PAD任务信息分页
            this.getPad();
        }
    }
    //获取生产任务信息
    getMession() {
        this._leadCockpitServiceProxy.getProductionAssignmentList(
            "CreationTime Desc",
            2,
            this.messionIndex
        )
        .pipe(finalize(() => { }))
            .subscribe(result => {
                this.rescueMsg1.title = result.items[0].title;
                this.rescueMsg1.sum = result.items[0].processRelationQuantity;
                this.rescueData1 = 
                {
                    labels: ['已完成', '未开始', '执行中'],
                    datasets: [
                        {
                            data: result.items[0].percent,
                            backgroundColor: [
                                "#FF6384",
                                "#36A2EB",
                                "#FFCE56"
                            ],
                            hoverBackgroundColor: [
                                "#FF6384",
                                "#36A2EB",
                                "#FFCE56"
                            ]
                        }
                    ],
                };
                
                if (result.items.length!=2) {
                    this.rescueMsg2.title = null;
                    this.rescueMsg2.sum = null;
                    this.rescueData2 = {};
                } else {
                    this.rescueMsg2.title = result.items[1].title;
                    this.rescueMsg2.sum = result.items[1].processRelationQuantity;
                    this.rescueData2 = {
                        labels: ['已完成', '未开始', '执行中'],
                        datasets: [
                            {
                                data:result.items[1].percent,
                                backgroundColor: [
                                    "#FF6384",
                                    "#36A2EB",
                                    "#FFCE56"
                                ],
                                hoverBackgroundColor: [
                                    "#FF6384",
                                    "#36A2EB",
                                    "#FFCE56"
                                ]
                            }
                        ],
                    }
                }
                if (this.messionIndex+2>=result.totalCount) {
                    this.messionFlag = true;
                } else {
                    this.messionFlag = false;
                }
        });
    }
    //质量采集信息
    getCollection() {
        this._leadCockpitServiceProxy.getQualityCollectionInfo()
        .pipe(finalize(() => { }))
            .subscribe(result => {
                this.barData1 = {
                    labels: result.productName,
                    datasets: [
                        {
                            label: '总项数',
                            backgroundColor: '#42A5F5',
                            borderColor: '#1E88E5',
                            data: result.qualityData
                        },
                        {
                            label: '已采项数',
                            backgroundColor: '#9CCC65',
                            borderColor: '#7CB342',
                            data: result.qualityCollectionData
                        }
                    ]
                };
        });
    }
    //多媒体
    getMute() {
        this._leadCockpitServiceProxy.getMultiMediaCollectionInfo()
        .pipe(finalize(() => { }))
            .subscribe(result => {
                this.barData2 = {
                    labels: result.productName,
                    datasets: [
                        {
                            label: '总项数',
                            backgroundColor: '#42A5F5',
                            borderColor: '#1E88E5',
                            data: result.multiMediaData
                        },
                        {
                            label: '已采项数',
                            backgroundColor: '#9CCC65',
                            borderColor: '#7CB342',
                            data: result.multiMediaCollectionData
                        }
                    ]
                };
        });
    }
    //PAD信息
    getPad() {
        // abp.ui.setBusy(undefined, '', 1);
        this._leadCockpitServiceProxy.getPadInfoList(
            "CreationTime Desc",
            4,
            this.padIndex
        )
        .pipe(finalize(() => { }))
            .subscribe(result => {
                // abp.ui.clearBusy();
                this.padMsg = result.items;
                if (this.padIndex+2>=result.totalCount) {
                    this.padFlag = true;
                } else {
                    this.padFlag = false;
                }
        });
    }

}
